package UCM;

import Source.DeleteFlight;
import Views.ViewDeleteFlight;

/**
 *
 * @author Joshua King
 */
public class UCDeleteFlight implements UCController {
    
    private ViewDeleteFlight view;
    private DeleteFlight model = new DeleteFlight();

    public UCDeleteFlight(ViewDeleteFlight view) {
        this.view = view;
        view.loadTo(model);
    }

    /**
Precondition: The manager is logged in on the delete flights UI.

   1. Manager chooses a flight and clicks delete flight.
   2. System loads data to model.
   3. System deletes flight data.
   4. System updates the view flight UI indicating success. 

Postcondition: The flight is deleted.

Unsuccessful Outcomes:

    * 3a) System can't delete data.
         1. System updates the UI informing the manager that the service is currently unavailable. 
    * 3b) System receives notice that an error has occurred.
         1. System updates the UI informing the manager that there was an internal error. 
     */
    public void run() {
        //2. System loads data to model.
        view.loadData();
        //3. System deletes flight data.
        if (model.commitData()) {
            //4. System updates the view flight UI indicating success.
            view.refresh();
        } else {
//    * 3a) System can't delete data.
//         1. System updates the UI informing the manager that the service is currently unavailable. 
//    * 3b) System receives notice that an error has occurred.
//         1. System updates the UI informing the manager that there was an internal error.       
            view.updateFailure();
        }
        
    }
}
